package com.cskaoyan.service;

import com.cskaoyan.bean.user.SearchHistory;
import com.cskaoyan.bean.user.SearchHistoryExample;
import com.cskaoyan.mapper.SearchHistoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dww
 */

@Service
public class HistoryServiceImpl implements HistoryService {
    @Autowired
    private SearchHistoryMapper searchHistoryMapper;

    public List<SearchHistory> getHistoryList(Integer page, Integer limit, String sort, String order, String keyWord, Integer userId) {
        PageHelper.startPage(page,limit,sort +" " + order);
        SearchHistoryExample example = new SearchHistoryExample();
        SearchHistoryExample.Criteria criteria = example.createCriteria();
        if(StringUtil.isNotEmpty(keyWord)){ criteria.andKeywordLike("%"+keyWord+"%"); }
        if(userId != null){ criteria.andUserIdEqualTo(userId); }
        return searchHistoryMapper.selectByExample(example);
    }
}
